;-*- coding: utf-8 -*-
; Fritz Kunze's emacs init file.
; 2008-08
; 
; 

(add-to-list 'load-path "~/.emacs.d")


;----
; loading custom commands and functions in ~/.emacs.d
;



(message "hey fritz - we are now processing our ~/.emacs.d/init.el")

(message "hey fritz - we are loading the file ~\\.emacs.d\\init.el")

(message "hey fritz - we are loading our emacs keyboard shortcuts")

(load-file (w32-short-file-name "~/.emacs.d/keyboard.el"))


(message "hey fritz - we've finished loading our emacs keyboard shortcuts")

(message "hey fritz - we are loading our emacs_abbrevs.el")

(load-file (w32-short-file-name "~/.emacs.d/emacs_abbrevs.el"))

(message "hey fritz - we've finished loading our emacs_abbrevs.el")

(message "hey fritz - we are loading our elisp_util.el")

(load-file (w32-short-file-name "~/.emacs.d/elisp_util.el"))

(message "hey fritz - we've finished loading our elisp_util.el")

(message "hey fritz - we are loading our rst_mods.el which add functionality to rst-mode")

(load-file (w32-short-file-name "~/.emacs.d/rst_mods.el"))

(message "hey fritz - we've finished loading our rst_mode.el")

(message "hey fritz - we are trying to make recent files possible")
;; the next code works, but i decided to use the ido code instead whic
;; follows the commented code, and i found at this location
;; http://www.emacswiki.org/emacs-en/RecentFiles#toc5

;;(require 'recentf)
;;(recentf-mode 1)
;;(setq recentf-max-menu-items 40)
;;(global-set-key "\C-x\ \C-r" 'recentf-open-files)

(defun recentf-ido-find-file ()
  "Find a recent file using Ido."
  (interactive)
  (let* ((file-assoc-list
	  (mapcar (lambda (x)
		    (cons (file-name-nondirectory x)
			  x))
		  recentf-list))
	 (filename-list
	  (remove-duplicates (mapcar #'car file-assoc-list)
			     :test #'string=))
	 (filename (ido-completing-read "Choose recent file: "
					filename-list
					nil
					t)))
    (when filename
      (find-file (cdr (assoc filename
			     file-assoc-list))))))

(global-set-key "\C-x\ \C-r" 'recentf-ido-find-file)

(message "hey fritz - we finished load code to make recent files possible")

;(message "hey fritz - we are loading xah lee's command-frequence.el package to figure out which commands we use the most")

;; Set up a way to keep track of command frequencies I use in emacs
;; taken from http://xahlee.org/emacs/command-frequency.html
;; and http://nflath.com/2009/08/command-frequency-mode/
;; and later I took an update to command-frequency.el from 
;; http://code.google.com/p/ergoemacs/source/browse/trunk/packages/command-frequency.el?spec=svn200&r=200


;(load-file (w32-short-file-name "~/.emacs.d/command-frequency.el"))

;;(setq-default command-frequency-table-file (w32-short-file-name "~/.emacs.d/frequencies"))
;(require 'command-frequency)
;(command-frequency-mode 1)
;(command-frequency-table-load)
;(command-frequency-autosave-mode 1)


;;(message "hey fritz - we've finished loading command-frequence.el")


;; To load custom changes to emacs, put them in your own directory and load packages out of this directory first.  This way, emacs will load changes you add, and ignore packages with the same name when it loads from the default load path. 


	

;; I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start) and that is causing an error with the message The directory ~/.emacs.d/server is unsafe. Has anyone seen this and know a fix or workaround? ... other than leaving server turned off ;)

;; Here is the stack trace:

;; Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe")
;;   signal(error ("The directory ~/.emacs.d/server is unsafe"))
;;   error("The directory %s is unsafe" "~/.emacs.d/server")
;;   server-ensure-safe-dir("~\\.emacs.d\\server\\")
;;   server-start(nil)
;;   call-interactively(server-start t nil)
;;   execute-extended-command(nil)
;;   call-interactively(execute-extended-command nil nil)

;; This is a known Emacs bug on Windows. A workaround is to comment out this line in server-ensure-safe-dir in server.el the you'll want to byte recompile after the change:

;; ;; FIXME: Busted on Windows. 
;; ;; (eql (nth 2 attrs) (user-uid))

;; To avoid hacking in the lisp directory, you can just add the following to your .emacs:

;; (and (= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))



;;(and (= emacs-major-version 23) (defun server-ensure-safe-dir (dir) "Noop" t))
(server-start)

(message "hey fritz - we've set up runemacs and emacsclientw.exe")

(require 'help-fns+)

(message "hey fritz - we've set up help-fns.el - an easier way to read help on emacs")

;; get an indication of when the end of file occurs - note this is a strange lisp form...
(setq-default indicate-empty-lines t)

;; The following customization will tell remember to use org files as
;; target, and to create annotations compatible with Org-mode links.

(setq org-directory "~/OrgProjects")
(setq org-default-notes-file "~/OrgProjects/.notes")

(add-to-list 'load-path "~/.emacs.d/org-6.35i/lisp")
(add-to-list 'load-path "~/.emacs.d/org-6.35i/contrib/lisp")

(setq org-completion-use-ido t)


;; The following lines are always needed.  Choose your own keys.
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
;;
;; Furthermore, you must activate font-lock-mode in Org buffers, because significant functionality depends on font-locking being active.
;; You can do this with either one of the following two lines 
;;   (global-font-lock-mode 1)                     ; for all buffers
;;   (add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
;;
;; (add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only

;;(global-font-lock-mode 1)                     ; use for all buffers
(add-hook 'org-mode-hook 'turn-on-font-lock)  ; Org buffers only
;;;With this setup, all files with extension ‘.org’ will be put into Org mode. 

;; set up org publishing following: 
;; http://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.php
;;


(message "hey fritz - org mode loading is done - try out - M-x org-mde see: C:\NP1\Get Organized with Emacs Org-mode.htm")

(message "hey fritz - we are loading our org-projects.el which defines how we publish org-mode files")

(load-file (w32-short-file-name "~/.emacs.d/org-projects.el"))

(message "hey fritz - we've finished loading our org-projects.el")

(message "hey fritz - we are loading our iimage.el allowing us to inline images into org and other files")

(load-file (w32-short-file-name "~/.emacs.d/iimage.el"))
(autoload 'iimage-mode "iimage" "Support Inline image minor mode." t)
(autoload 'turn-on-iimage-mode "iimage" "Turn on Inline image minor mode." t)
(add-hook 'info-mode-hook 'turn-on-iimage-mode)
;;
;; .texinfo:   @file{file://foo.png}
;; .info:      `file://foo.png'
;;
;; ** Display images in Wiki buffer.
;;
(add-hook 'wiki-mode-hook 'turn-on-iimage-mode)
;;
;; wiki-file:   [[foo.png]]

(message "hey fritz - we've finished loading our iimage.el allowing us to inline images into org and other files")

(message "hey fritz - we are loading our org-utils.el which add some convenient keyboard shortcuts to work with images and a few other goodies")

;(load-file (w32-short-file-name "~/.emacs.d/org-utils.el"))

(message "hey fritz - we've finished loading our org-utils.el")

(defalias 'list-buffers 'ibuffer)
(message "hey fritz - you just replaced list-buffers with ibuffer")

   
(message "hey fritz - we are fixing an emacs bug such that when you open a “.xml” file, the file is opened with the old xml mode the sgm-mode, not nxml-mode")

(add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))


;;; this must be loaded after the (load ... eli/fi-site-init.el) 
;;; to solve a compatibilty problem

(setq fi:eli-compatibility-mode nil)

(defun alisp ()
  (interactive)
  (let ((lisp-directory "C:\\Program Files\\acl81\\")
        (lisp-name "mlisp"))
    (fi:common-lisp (format "*%s*" lisp-name)
                    lisp-directory
                    (format "%s\\%s.exe" lisp-directory lisp-name)
                    (list "+B" "+cx" "+M")
                    fi:common-lisp-host
                    (format "%s.dxl" lisp-name))))



(defun add-to-load-path (path-string)
  (message (format "Passed %S..." path-string))
  (if (stringp path-string)
      (when (file-exists-p path-string)
	(message (format "Adding %S to load-path..." path-string))
	(add-to-list 'load-path (expand-file-name path-string)))
    (crs-add-to-load-path (car path-string))
    (if (cdr path-string)
	(crs-add-to-load-path (cdr path-string)))))


(message "Initialization complete") (sit-for 1)
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(abbrev-mode t)
 '(column-number-mode t)
 '(current-language-environment "UTF-8")
 '(default-frame-alist (quote ((font . "-outline-Courier New-normal-r-normal-normal-21-157-96-96-c-*-iso8859-1") (top . 10) (left . 150) (tool-bar-lines . 1) (menu-bar-lines . 1) (right-fringe) (left-fringe))))
 '(doc-view-ghostscript-program (executable-find "mgs"))
 '(focus-follows-mouse nil)
 '(global-visual-line-mode t)
 '(grep-command "C:\\Windows\\System32\\findstr.exe -n -r  ")
 '(grep-use-null-device t)
 '(gud-pdb-command-name "python -m pdb")
 '(icicle-reminder-prompt-flag 0)
 '(ido-mode (quote both) nil (ido))
 '(inhibit-startup-echo-area-message "fkunze")
 '(inhibit-startup-screen t)
 '(ispell-program-name "C:\\Program Files\\Aspell\\bin\\aspell.exe")
 '(mouse-autoselect-window t)
 '(mouse-wheel-follow-mouse t)
 '(org-agenda-files (quote ("~/Org/personal.org")))
 '(org-support-shift-select t)
 '(python-python-command "C:/Python25/python.exe")
 '(recentf-max-saved-items 40)
 '(safe-local-variable-values (quote ((Package . NEWSCADE))))
 '(show-paren-mode t)
 '(text-mode-hook (quote (turn-on-flyspell text-mode-hook-identify))))
(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "SystemWindow" :foreground "SystemWindowText" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 158 :width normal :foundry "outline" :family "Arial Unicode MS")))))



(put 'upcase-region 'disabled nil)

(put 'downcase-region 'disabled nil)

(put 'narrow-to-region 'disabled nil)
